/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author automne
 */
@Stateless(mappedName="ejb.ScoreFacade")
public class ScoreFacade implements ScoreFacadeRemote {
    @PersistenceContext
    private EntityManager em;

    public void create(Score score) {
        em.persist(score);
    }

    public void edit(Score score) {
        em.merge(score);
    }

    public void remove(Score score) {
        em.remove(em.merge(score));
    }

    public Score find(Object id) {
        return em.find(Score.class, id);
    }

    public List<Score> findAll() {
        return em.createQuery("select object(o) from Score as o").getResultList();
    }

    public List<Score> orderByHighestScore() {
        return em.createQuery("select object(o) from Score as o order by o.highestScore DESC").getResultList();
    }

    public List<Score> orderByTotalScore() {
        return em.createQuery("select object(o) from Score as o order by o.totalScore DESC").getResultList();
    }

}
